package com;

import com.dao.UserDao;
import com.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration//说明本类是配置文件
@ComponentScan//扫描整个项目的bean
@EnableAspectJAutoProxy//开启切面代理

@Configuration
@ComponentScan
@EnableAspectJAutoProxy
@EnableWebMvc
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        UserService userService =context.getBean(UserService.class);
        boolean flag = userService.login("张三","123");
        if(flag){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }
        UserDao userDao = context.getBean(UserDao.class);
        userDao.insert();
        userDao.delete();
        userDao.select();
        userDao.update();
        @Bean
        public InternalResourceViewResolver viewResolver() {
            InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
            viewResolver.setPrefix("/WEB-INF/pages/");//模板文件位置
            viewResolver.setSuffix(".jsp");// 自动解析后缀名
            return viewResolver;
        }
    }